//
//  HomeSearchCell.m
//  ReceiptDelivery
//
//  Created by 吕晶 on 2020/11/17.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "HomeSearchCell.h"
#import "HomeSearchModel.h"

@interface HomeSearchCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *wordLab;
@property (nonatomic, strong) UIButton *deleteBtn;
@property (nonatomic, strong) UIButton *wordBtn;

@end

@implementation HomeSearchCell

+ (instancetype)HomeSearchCellWithReuseIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath withCollectionView:(UICollectionView *)collectionView {
    HomeSearchCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[HomeSearchCell alloc] init];
    }
    return cell;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xF2F2F5);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 4;
        [self.contentView addSubview:self.bgView];
        
        self.wordLab = [UILabel new];
        self.wordLab.textColor = HexColor(0x585974);
        self.wordLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.wordLab];
        
        self.deleteBtn = [UIButton new];
        [self.deleteBtn setImage:[UIImage imageNamed:@"icon_delete"] forState:0];
        [self.deleteBtn addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.deleteBtn];
        
        self.wordBtn = [UIButton new];
        [self.wordBtn addTarget:self action:@selector(wordClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.wordBtn];
    }
    return self;
}

-(void)setFrameModel:(HomeSearchFrame *)frameModel {
    _frameModel = frameModel;
    [self configUI];
}

- (void)configUI {
    self.bgView.frame = self.frameModel.bgF;
    self.wordLab.frame = self.frameModel.wordF;
    self.deleteBtn.frame = self.frameModel.deleteF;
    self.wordLab.text = self.frameModel.wordModel.wordText;
    self.wordBtn.frame = self.frameModel.wordF;
}

- (void)deleteClick {
    if (self.deleteBlock) {
        self.deleteBlock();
    }
}

- (void)wordClick {
    if (self.wordBlock) {
        self.wordBlock(self.frameModel.wordModel.wordText);
    }
}

@end
